package thread;

// 前台线程, 后台线程
public class demo7 {
/*    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t 线程结束");
        });

        t.start();

        Thread.sleep(1000);
        System.out.println("主线程结束");
    }*/

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t 线程结束");
        });

        // 在 start 之前, 把 t 设定为后台线程
        // 设置 守护线程
        t.setDaemon(true);

        t.start();

        Thread.sleep(1000);
        System.out.println("主线程结束");
    }

}
